package sort;

import common.Print;

/**
 * 选择排序
 */
public class SelectionSort {

    public static void main(String[] args) {
        int[] arr = {3,5,2,4,15,19,25,47,26,27,2,46,4,19,48,50};
        sort(arr);
        Print.printArr(arr);
    }

    public static void sort(int[] arr){
        for (int i = 0; i < arr.length-1; i++) {
            int first = arr[i];
            int position = i;
            for (int j = i+1; j < arr.length-1; j++) {
                if(first > arr[j]){
                    first = arr[j];
                    position = j;
                }
            }
            if(position != i){
                int temp = arr[i];
                arr[i] = first;
                arr[position] = temp;
            }
        }
    }
}
